import { ElMessage } from 'element-plus';


export default class VoiceRecordUnit {


    private  static synth:any;
    constructor(){
    }
    public static init(){
        this.synth = window.speechSynthesis;
		
	    // const msg = new SpeechSynthesisUtterance();
        // msg.text = '你好 给你点👍';
	    // msg.lang = 'zh-CN';
        // this.synth.speak(msg);
        // this.synth.addEventListener('voiceschanged',()=>{
        //     let voices = this.synth.getVoices();
        //     console.log("synth getVoices = ",voices);
        //     for (const vo of voices) {
        //         if(vo.)
        //         {

        //         }
        //     }
        // });
        // setInterval(()=>{
        //     console.log("synth.speaking = ",this.synth.speaking);
        // },1000)
    }




    public static speak(warnContent:string){
			const msg = new SpeechSynthesisUtterance();
			warnContent=warnContent.replace(new RegExp("{}",'g'),'');
			msg.text = warnContent;
			msg.lang = 'zh-CN';
			// msg.text = 'hello world';
			// msg.lang = 'en-US';
			this.synth.speak(msg);
		
       


    }
	public static get isRecording():boolean{
		return this.synth.speaking;
	}

    // public static getSupportVoices() {
	// 	let voices = this.synth.getVoices()
	// 	voices.forEach(e => {
	// 		const option = document.createElement('option')
	// 		option.value = e.lang
	// 		option.text = e.name
	// 		voicesDropdown.appendChild(option)
	// 	 })
	// }
	// public static handleSpeak(e) {
	// 	msg.lang = voicesDropdown.selectedOptions[0].value
	// 	synth.speak(msg)
	// }
	// public static handleStop(e) {
	// 	synth.cancel(msg)
	// }
	// public static handleChange(e) {
	// 	msg[this.name] = this.value
	// }
	// public static throttle(fn,delay) {
	// 	let last = 0
	// 	return function() {
	// 		const now = new Date()
	// 		if(now - last > delay) {
	// 			fn.apply(this,arguments)
	// 			last = now
	// 		}
	// 	}
	// }
    // const synth = window.speechSynthesis
	// const msg = new SpeechSynthesisUtterance()
	// let voices = []
	// const voicesDropdown = document.querySelector('[name="voice"]')
	// const options = document.querySelectorAll('[type="range"], [name="text"]')
	// const speakButton = document.querySelector('#speak')
	// const stopButton = document.querySelector('#stop')

	// msg.text = '你好 给你点👍'
	// msg.lang = 'zh-CN'

	// synth.addEventListener('voiceschanged',getSupportVoices)
	// speakButton.addEventListener('click',throttle(handleSpeak,1000))
	// stopButton.addEventListener('click',handleStop)
	// options.forEach(e => e.addEventListener('change',handleChange))
}